package com.example.mall.web.controller;

import com.example.mall.domain.CouponActivity;
import com.example.mall.dto.CouponActivityDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.CouponActivityQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ICouponActivityService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/couponActivity")
public class CouponActivityController {

    @Autowired
    public ICouponActivityService couponActivityService;

    /**
     * 分页查询优惠券活动表信息
     * @param couponActivityQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询优惠券活动表信息",notes = "分页查询优惠券活动表信息",httpMethod = "GET")
    public JSONResult queryPage(CouponActivityQuery couponActivityQuery){
        PageDTO<CouponActivityDto> couponActivityDtoPageDTO = couponActivityService.queryPage(couponActivityQuery);
        return JSONResult.success("查询成功",couponActivityDtoPageDTO);
    }

    /**
     * 根据id查询优惠券活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("query/{activityId}")
    @ApiOperation(value = "根据id查询优惠券活动表信息",notes = "根据id查询优惠券活动表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.ACTIVITYID_NOT_ID);
        }
        CouponActivity couponActivity = couponActivityService.getById(activityId);
        return JSONResult.success("查询成功",couponActivity);
    }

    /**
     * 根据id查询优惠券活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("queryCouponActivityById/{activityId}")
    @ApiOperation(value = "根据id查询优惠券活动表信息",notes = "根据id查询优惠券活动表信息",httpMethod = "GET")
    public JSONResult queryCouponActivityById(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.ACTIVITYID_NOT_ID);
        }
        CouponActivity couponActivity = couponActivityService.queryCouponActivityById(activityId);
        return JSONResult.success("查询成功",couponActivity);
    }

    /**
     * 查询全部优惠券活动表信息
     * @param
     * @return
     */
    @GetMapping("queryCouponActivityList")
    @ApiOperation(value = "查询全部优惠券活动表信息",notes = "查询全部优惠券活动表信息",httpMethod = "GET")
    public JSONResult queryCouponActivityList(){
        List<CouponActivity> couponActivities = couponActivityService.queryCouponActivityList();
        return JSONResult.success("查询成功",couponActivities);
    }

    /**
     * 新增优惠券活动表
     * @param couponActivityDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增优惠券活动表",notes = "新增优惠券活动表",httpMethod = "POST")
    public JSONResult insert(@RequestBody CouponActivityDto couponActivityDto){
        couponActivityService.insert(couponActivityDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改优惠券活动表信息
     * @param couponActivityDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改优惠券活动表信息",notes = "修改优惠券活动表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody CouponActivityDto couponActivityDto){
        couponActivityService.update(couponActivityDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除优惠券活动表信息
     * @param activityId
     * @return
     */
    @PostMapping("delete/{activityId}")
    @ApiOperation(value = "删除优惠券活动表信息",notes = "删除优惠券活动表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activityId") Long activityId) {
        couponActivityService.delete(activityId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除优惠券活动表信息
     * @param activityIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除优惠券活动表信息",notes = "批量删除优惠券活动表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> activityIds) {
        couponActivityService.deleteBatch(activityIds);
        return JSONResult.success("批量删除成功");
    }
}
